﻿using System.Text.RegularExpressions;

namespace RayD.Core
{
    /// <summary>
    /// 字符串拓展
    /// </summary>
    public static partial class Extention
    {
        #region 帕斯卡命名转换
        /// <summary>
        /// By default, pascalize converts strings to UpperCamelCase also removing underscores
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string Pascalize(this string input)
        {
            //"some_title".Pascalize() => "Some_Title"
            input = input.ToLower();
            return Regex.Replace(input, "(?:^|_)(.)", match => match.Groups[0].Value.ToUpper());
        }
        #endregion

        #region 驼峰命名转换
        /// <summary>
        ///  Same as Pascalize except that the first character is lower case
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string Camelize(this string input)
        {
            //"some_title".Pascalize() => "some_Title"
            var word = Pascalize(input);
            return word.Substring(0, 1).ToLower() + word.Substring(1);
        }
        #endregion
    }
}
